<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="imgs/bai.ico"/>
    <link rel="Shortcut Icon" href="imgs/bai.ico"/>
    <title>管理后台登录</title>
    <style type="text/css">
        body { margin: 0; padding: 0; background: #eee; }
        #form { margin: 10% auto; width: 300px; }
        #form input { margin: 10px; padding: 10px; width: 260px; border: 1px solid #ccc; border-radius: 3px; }
        #submit { margin: 20px auto; padding: 10px; width: 200px; background: #0088cc; text-align: center; color: #fff; border-radius: 3px; cursor: pointer; }
        #submit:hover { background: #80d4ff; }
        #errMsg { margin: 0 40px; color: red; font-size: 12px; text-align: center; }
    </style>
</head>
<body>
    <div id="form">  
        <input type="text" id="uname" placeholder="填写账号"/>
        <input type="password" id="upwd" placeholder="填写密码"/>
        <p id="errMsg"></p>
        <div id="submit" onclick="dologin();">马上登录</div>
    </div>

    <!-- msg弹窗 -->
    <span id="msgPop"></span>
</body>
</html>


<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/view.js"></script>
<script type="text/javascript">
    // 登录
    function dologin(){
        var uname = $('#uname').val();
        var upwd = $('#upwd').val();
        var errDiv = $('#errMsg');
        if (uname == '') {
            errDiv.html('昵称必填');
            msgPop({msg: '昵称必填'}); return
        }
        if (upwd == '') {
            errDiv.html('密码必填');
            msgPop({msg: '密码必填'}); return
        }
        console.log(uname, upwd);
        var formData = {
            uname: uname, 
            passwd: upwd
        };
//        console.log(formData);
        $.ajax({
            type: apis.login.method,
            url: apis.login.url,
            data: formData,
            success: function (res) {
                console.log(res);
                if (res.code != 0) {
                    errDiv.html(res.msg);
                    msgPop({msg: res.msg}); return
                }
                msgPop({msg: '登录成功'});
                var adminInfo = {
                    aid: res.data.aid,
                    adminName: res.data.adminName,
                    currYmd: currYmd()
                };
                setAdminInfo({val: adminInfo});
                window.location.href = routes.index;
            },
            error: function () {
                console.log('网络错误');
            }
        });
    }
</script>